package com.stella.ieproductivitybackend.controller;

import com.stella.ieproductivitybackend.entity.*;
import com.stella.ieproductivitybackend.service.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 品牌页控制层
 */
@RestController
@RequestMapping("/brand")
public class BrandController {
    @Autowired
    private BrandService brandService;

    /**
     * 工厂列表
     */
    @PostMapping("/getFactoryList")
    public List<Factory> getFactoryList(@RequestBody Map<String, Object> param) {
        String brand = param.get("brand") != null ? param.get("brand").toString() : "";
        return brandService.getFactoryList(brand);
    }

    /**
     * 品牌列表
     */
    @PostMapping("/getBrandList")
    public List<Brand> getBrandList() {
        return brandService.getBrandList();
    }

    /**
     * 品牌系列
     */
    @PostMapping("/getBrandSeries")
    public List<Brand> getBrandSeries(@RequestBody Map<String, Object> params) {
        String brand = params.get("brand") != null ? params.get("brand").toString() : "";
        return brandService.getBrandSeries(brand);
    }

    /**
     * 型体数量
     */
    @PostMapping("/getModelCount")
    public Integer getModelCount(@RequestBody Map<String, Object> params) {
        String brand = params.get("brand") != null ? params.get("brand").toString() : "";
        return brandService.getModelCount(brand);
    }

    /**
     * 型体列表
     */
    @PostMapping("/getModelList")
    public List<Model> getModelList(@RequestBody Map<String, String> params) {
        String brand = params.get("brand") != null ? params.get("brand") : "";
        return brandService.getModelList(brand);
    }

    /**
     * 搜索型体
     */
    @PostMapping("/searchModel")
    public List<Model> searchModel(@RequestBody Map<String, Object> params) {
        String brand = params.get("brand") != null ? params.get("brand").toString() : "";
        String model = params.get("model") != null ? params.get("model").toString() : "";
        return brandService.searchModel(brand, model);
    }

    /**
     * 纯粹达成率图表
     */
    @PostMapping("/getPureChart")
    public Map<String, Object> getPureChart(@RequestBody Map<String, Object> params) {
        String brand = params.get("brand") != null ? params.get("brand").toString() : "";
        return brandService.getPureChart(brand);
    }

    /**
     * 纯粹达成率详情
     */
    @PostMapping("/getPureDetail")
    public Map<String, Map<String, Map<String, Map<String, Integer>>>> getPureDetail(@RequestBody Map<String, Object> params) {
        String brand = params.get("brand") != null ? params.get("brand").toString() : "";
        return brandService.getPureDetail(brand);
    }

    /**
     * 入库标准秒值图表
     */
    @PostMapping("/getWarehousingChart")
    public Map<String, Object> getWarehousingChart(@RequestBody Map<String, Object> params) {
        String brand = params.get("brand") != null ? params.get("brand").toString() : "";
        return brandService.getWarehousingChart(brand);
    }

    /**
     * 入库标准秒值图表详情
     */
    @PostMapping("/getWarehousingInfo")
    public Map<String, List<Warehousing>> getWarehousingInfo(@RequestBody Map<String, Object> params) {
        String brand = params.get("brand") != null ? params.get("brand").toString() : "";
        return brandService.getWarehousingInfo(brand);
    }

    /**
     * 入库标准秒值其他数据
     */
    @PostMapping("/getWarehousingOther")
    public Map<String, Object> getWarehousingOther(@RequestBody Map<String, Object> params) {
        String brand = params.get("brand") != null ? params.get("brand").toString() : "";
        return brandService.getWarehousingOther(brand);
    }

    /**
     * 入库标准秒值详情
     */
    @PostMapping("/getWarehousingDetail")
    public List<Warehousing> getWarehousingDetail(@RequestBody Map<String, Object> params) {
        String brand = params.get("brand") != null ? params.get("brand").toString() : "";
        String factory = params.get("factory") != null ? params.get("factory").toString() : "";
        String year = params.get("year") != null ? params.get("year").toString() : "";
        return brandService.getWarehousingDetail(brand, factory, year);
    }

    /**
     * 入库标准秒值对比
     */
    @PostMapping("/getWarehousingCompare")
    public List<Warehousing> getWarehousingCompare(@RequestBody Map<String, Object> params) {
        String brand = params.get("brand") != null ? params.get("brand").toString() : "";
        String factory1 = params.get("factory1") != null ? params.get("factory1").toString() : "";
        String year1 = params.get("year1") != null ? params.get("year1").toString() : "";
        String month1 = params.get("month1") != null ? params.get("month1").toString() : "";
        String factory2 = params.get("factory2") != null ? params.get("factory2").toString() : "";
        String year2 = params.get("year2") != null ? params.get("year2").toString() : "";
        String month2 = params.get("month2") != null ? params.get("month2").toString() : "";
        return brandService.getWarehousingCompare(brand, factory1, year1, month1, factory2, year2, month2);
    }

    /**
     * 入库数量图表
     */
    @PostMapping("/getQuantityChart")
    public Map<String, Object> getQuantityChart(@RequestBody Map<String, Object> params) {
        String brand = params.get("brand") != null ? params.get("brand").toString() : "";
        return brandService.getQuantityChart(brand);
    }

    /**
     * 入库数量详情
     */
    @PostMapping("/getQuantityDetail")
    public Map<String, List<Quantity>> getQuantityDetail(@RequestBody Map<String, Object> params) {
        String brand = params.get("brand") != null ? params.get("brand").toString() : "";
        return brandService.getQuantityDetail(brand);
    }

    /**
     * 直工 PPH 选项
     */
    @PostMapping("/getDirectOption")
    public Map<String, Object> getDirectOption(@RequestBody Map<String, Object> params) {
        String brand = params.get("brand") != null ? params.get("brand").toString() : "";
        return brandService.getDirectOption(brand);
    }

    /**
     * 直工PPH
     */
    @PostMapping("/getDirectPPH")
    public List<DirectPPH> getDirectPPH(@RequestBody Map<String, Object> params) {
        String brand = params.get("brand") != null ? params.get("brand").toString() : "";
        String factory = params.get("factory") != null ? params.get("factory").toString() : "";
        String year = params.get("year") != null ? params.get("year").toString() : "";
        String month = params.get("month") != null ? params.get("month").toString() : "";
        String model = params.get("model") != null ? params.get("model").toString() : "";
        String operation = params.get("operation") != null ? params.get("operation").toString() : "";
        return brandService.getDirectPPH(brand, factory, year, month, model, operation);
    }
}
